#pragma once

#include <QtCore/QString>

#include "Export.hpp"

namespace Qt
{
	enum class PortShape
	{
		Point,
		Bullet,
		Diamond,
		HollowDiamond
	};

	struct NodeDataType
	{
		QString id;
		QString name;
		PortShape shape;
	};

	enum class PortType
	{
		None,
		In,
		Out
	};

	enum class CntType
	{
		Link,
		Break
	};

	static const int INVALID_PORT = -1;

	using PortIndex = int;

	struct Port
	{
		PortType type;

		PortIndex index;

		Port()
			: type(PortType::None)
			, index(INVALID_PORT)
		{}

		Port(PortType t, PortIndex i)
			: type(t)
			, index(i)
		{}

		bool
			indexIsValid() { return index != INVALID_PORT; }

		bool
			portTypeIsValid() { return type != PortType::None; }
	};

	//using PortAddress = std::pair<QUuid, PortIndex>;

	inline
		PortType
		oppositePort(PortType port)
	{
		PortType result = PortType::None;

		switch (port)
		{
		case PortType::In:
			result = PortType::Out;
			break;

		case PortType::Out:
			result = PortType::In;
			break;

		default:
			break;
		}

		return result;
	}

	/// Class represents data transferred between nodes.
	/// @param type is used for comparing the types
	/// The actual data is stored in subtypes
	class NODE_EDITOR_PUBLIC QtNodeData
	{
	public:

		virtual ~QtNodeData() = default;

		virtual bool sameType(QtNodeData& nodeData) const
		{
			return (this->type().id == nodeData.type().id);
		}

		/// Type for inner use
		virtual NodeDataType type() const = 0;

		CntType connectionType() {
			return cType;
		}

		void setConnectionType(CntType t) {
			cType = t;
		}

	private:
		CntType cType = CntType::Link;
	};
}
